#ifndef FLOWER_H
#define FLOWER_H
#include <irrlicht.h>
#include "Game.h"

using namespace irr;
using namespace scene;
using namespace core;
using namespace video;

class C_IrrIANodes
{ 
public:

	IAnimatedMesh			*mesh;
	IAnimatedMeshSceneNode	*node; 

	ISceneNode				*snode;
};


class Game;

class Flower : public scene::ISceneNode
{
public:
	core::aabbox3d<f32> Box;
	video::SMaterial Material;

public:
	C_IrrIANodes	Nodes;
	C_IrrIANodes	Petal;
	bool			isOnLeftSide;


	~Flower()
	{

	}
	Flower(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, bool onLeftSide, int &petalType )
		: scene::ISceneNode(parent, mgr, id)
	{
		isOnLeftSide = onLeftSide;

		Nodes.mesh = Game::mDevice->getSceneManager()->getMesh("../DataGame/Flower_1.X");

		if( !Nodes.mesh ) return;

		Nodes.node = Game::mDevice->getSceneManager()->addAnimatedMeshSceneNode( Nodes.mesh );

		{
			Nodes.node->setParent( this );

			Nodes.node->setScale	(  vector3df( 5,5,5 ) );
			Nodes.node->setRotation ( vector3df( 0, 90, 0 ) );
			u8 emit = 64;
			for( u32 m = 0;  m < Nodes.node->getMaterialCount();  m++ )
			{
				Nodes.node->getMaterial( m ).EmissiveColor.set( 255,  emit, emit, emit );

				Nodes.node->getMaterial( m ).NormalizeNormals = true;
			}

			Nodes.node->setMaterialType( EMT_TRANSPARENT_ALPHA_CHANNEL );
		}

		Petal.mesh = Game::mDevice->getSceneManager()->getMesh("../DataGame/FlowerPet_1.X");
		if( !Petal.mesh ) return;

		Petal.node = Game::mDevice->getSceneManager()->addAnimatedMeshSceneNode( Petal.mesh );


		{
			Petal.node->setParent( this );
			Petal.node->setScale(  vector3df( 2,2,2 ) * 1.0f );
			Petal.node->setPosition(  vector3df( 0, 12.0f, 0 ) * 2 );
			Petal.node->setRotation( vector3df( 0, 0, 0 ) );

			if( isOnLeftSide ){ Petal.node->setRotation(  vector3df( 0, 0, 0 ) ); } 
			if( petalType == 0 ) { Petal.node->setMaterialTexture( 0, Game::mDevice->getVideoDriver()->getTexture("../DataGame/flower2.png") ); }

			u8 emit = 250;
			for( u32 m = 0;  m < Petal.node->getMaterialCount();  m++ )
			{
				Petal.node->getMaterial( m ).EmissiveColor.set( 255,  emit, emit, emit );
				Petal.node->getMaterial( m ).NormalizeNormals = true;
			}

			Petal.node->setMaterialType( EMT_TRANSPARENT_ALPHA_CHANNEL );
		}
	}


	virtual void OnRegisterSceneNode()
	{
		if( Nodes.node ){ Nodes.node->setVisible( IsVisible ); }
		if( Petal.node ){ Petal.node->setVisible( IsVisible ); }

		if (IsVisible)
			SceneManager->registerNodeForRendering(this);

		ISceneNode::OnRegisterSceneNode();
	}


	virtual void render()
	{

	}

	virtual const core::aabbox3d<f32>& getBoundingBox() const
	{ return Box; }

	virtual u32 getMaterialCount() const
	{ return 1; }

	virtual video::SMaterial& getMaterial(u32 i)
	{ return Material; }	

};

#endif